Issue in finding the backslash \ with an regular expression command

Hi all,

I have a problem with the regular expression statement, because actually I would like to avoid users to specify a baseline suffix including the escape character backslash \

Here is my code what I already tried, but now I have to give up and request your support. However it seems that the regular expression, match or keyword function can not detect the character backslash \.

Million thanks for your support. Please find attached my DXL test code including the test with an already working inverse logic, but I want to detect especially the backslash \ in the input string of the user.
WildThunderGuy - Thu Apr 01 05:24:38 EDT 2010

Re: Issue in finding the backslash \ with an regular expression command
Mathias Mamsch - Thu Apr 01 06:29:45 EDT 2010

Backslashed in regexp are tricky since the regular expression syntax wants you to escape the backslashes:

(C:\\.*) - will match to a path starting with C:\...

However when you encode that in a DXL string you need to escape each backslash again with a backslash:
 

Regexp re = regexp "c:\\\\(.*)"
string s = "c:\\DXL"
if (re s ) {
    print "Match found. Path on drive C: " s[match 1] "\n"
} else print "No match :-("

 


So to match a backslash in a rexexp you need to put 4 backslashes in there ...

Regards, Mathias

 

Re: Issue in finding the backslash \ with an regular expression command
WildThunderGuy - Tue Apr 06 05:47:06 EDT 2010

Mathias Mamsch - Thu Apr 01 06:29:45 EDT 2010

Backslashed in regexp are tricky since the regular expression syntax wants you to escape the backslashes:

(C:\\.*) - will match to a path starting with C:\...

However when you encode that in a DXL string you need to escape each backslash again with a backslash:
 

Regexp re = regexp "c:\\\\(.*)"
string s = "c:\\DXL"
if (re s ) {
    print "Match found. Path on drive C: " s[match 1] "\n"
} else print "No match :-("

 


So to match a backslash in a rexexp you need to put 4 backslashes in there ...

Regards, Mathias

 

Hi Mathias,

Thanks a lot for answering this question. It seems really trick with four backslashes in the regexp.

Best Regards.

Re: Issue in finding the backslash \ with an regular expression command
WildThunderGuy - Tue Apr 06 05:55:36 EDT 2010

Question answered, million thanks for your support.